package com.nd.controller;


import com.nd.common.result.ResultUtils;
import com.nd.entity.Desk;
import com.nd.entity.Users;
import com.nd.service.IDeskService;
import com.nd.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangqixing
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/desk")
public class DeskController {
    @Autowired
    IDeskService service;

    @GetMapping("/")
    public Object getList() {
        List<Desk>  list=service.list();
        return ResultUtils.returnSuccessLayui(list, list.size());
    }

    /**
     * 根据id查询单个
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Object getById(@PathVariable("id") Integer id) {
        return service.getById(id);
    }

    /**
     * 根据id删除单个
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Object del(@PathVariable("id") Integer id) {
        if (service.removeById(id)) {
            return ResultUtils.returnSuccess();
        } else {
            return ResultUtils.returnFail("删除失败");
        }
    }


    /**
     * 添加
     *
     * @param desk
     * @return
     */
    @PostMapping("/")
    public Object add(@RequestBody Desk desk) {
        if (service.save(desk)) {
            return ResultUtils.returnSuccess();
        } else {
            return ResultUtils.returnFail("添加失败");
        }
    }


    /**
     * 修改
     *
     * @param desk
     * @return
     */
    @PutMapping("/")
    public Object update(@RequestBody Desk desk) {
        if (service.updateById(desk)) {
            return ResultUtils.returnSuccess();
        } else {
            return ResultUtils.returnFail("修改失败");
        }
    }
}
